package ch.exm.storm.conditions;

public class Like extends TwoArgumentsCondition {

	public Like(Object first, Object second) {
		super(first, second);
	}
	
	@Override
	public boolean matches(Object firstValue, Object secondValue) {
		if (firstValue == null && secondValue == null) return true;
		if (firstValue == null || secondValue == null) return false;
		return firstValue.toString().matches(secondValue.toString().replace("%", ".*").replace("_", "."));
	}

	@Override
	protected String getConditionKeyword() {
		return (" like ");
	}
	
	@Override
	protected String getInverseConditionKeyword() {
		throw new UnsupportedOperationException("Can't invert a like condition");
	}

	public static Like areLike(Object first, Object second) {
		return new Like(first, second);
	}
}
